I need to load a view which has a complex filter and count the number of visible objects. Why doesn't the following code work (It counts the number of objects in the module ignoring the filter)?
Module m = read(fullName(i), false)
load(view "Myview")
Object o
int n = 0
for o in current Module do {n++}
print n
close(m, false)
mcnairk - Fri Jan 06 11:46:29 EST 2012 |
Re: Count objects in filtered view |
Re: Count objects in filtered view
One alternative I would suggest is to potentially approach this query from the prospective of the complex filter rather than the view. After all, the view is just a collection of attributes to display, it's the filter that identifies the content. Module mod = current Module int total_accepted = 0 int total_rejected = 0 Filter Reqt = (attribute "Requirement?" == "True") Filter Version = (attribute "Version" == "1") Filter Effectivity = (attribute "Effectivity" == "1.5") Filter Ver1Effcount = (Reqt && Version && Effectivity) set(current Module, Ver1Effcount, total_accepted, total_rejected)
|
Re: Count objects in filtered view smarti.sj - Fri Jan 06 11:51:44 EST 2012 |
Re: Count objects in filtered view BDavenport - Fri Jan 06 12:39:19 EST 2012
One alternative I would suggest is to potentially approach this query from the prospective of the complex filter rather than the view. After all, the view is just a collection of attributes to display, it's the filter that identifies the content. Module mod = current Module int total_accepted = 0 int total_rejected = 0 Filter Reqt = (attribute "Requirement?" == "True") Filter Version = (attribute "Version" == "1") Filter Effectivity = (attribute "Effectivity" == "1.5") Filter Ver1Effcount = (Reqt && Version && Effectivity) set(current Module, Ver1Effcount, total_accepted, total_rejected)
Many thanks, Ken. |
Re: Count objects in filtered view
You need "current = m" before "load(view "Myview")". If the module is already open I don't think the "read" command sets it current. And yes you cannot load a view in an invisible module.
const string cl_vStandard = "Standard view"
//*****************************************
bool fView_LoadView(Module p_mod, string p_NameView)
{ // Load the specified view in the open module, which can be either visible or invisible
// When NameView is null, presume to load the Standard view
// Always presume to ignore manual view changes if any.
// Calling programs may want to do this:
// for NameView in view(mod) do
// { if (!fView_LoadView(mod, NameView)) continue
// for col in mod do
// { deal with columns
// }
// } // end views in the Module
// Odd realities:
// When the module is already Visible, then you
// can 'load' the view, but re-opening the module does NOT load any view
// When the module is already INvisible, then you
// cannot 'load' the view, but re-opening the module does indeed load
// either the default view or the standard view.
// Thus, when invisible we temporarily change the default view for
// the user to the desired View, and change it back after
// reading the module, which loads the view.
// Also, when the standard view is loaded in this way, the
// name of the current view doesn't change, but the columns do.
if (null p_mod or
type(p_mod) != "Formal") return(false)
string NameToLoad, NameModFull, NameDefault, ErrMess
Item itm
View viu
bool LoadOK
Module mod1
if (null p_NameView or
p_NameView == cl_vStandard) //-
then NameToLoad = cl_vStandard
else NameToLoad = p_NameView
NameModFull = fullName(p_mod)
itm = item(NameModFull)
viu = view(itm, NameToLoad) // Gets handle even if view doesn't exist
if (null viu or
!canRead(viu))
LoadOK = false // No such view, or user cannot see it.
elseif(isVisible(p_mod))
{ noError()
LoadOK = load(p_mod, viu, false)
ErrMess = lastError()
}
elseif(NameToLoad == cl_vStandard)
{ // ** Invisible Mod, loading the Standard view
LoadOK = p_mod == (Module read(NameModFull, false, true)) // Open, option to read Standard View
}
else
{ // ** Invisible Mod, loading a user view
NameDefault = getDefaultViewForUser(p_mod)
ErrMess = setDefaultViewForUser(p_mod, p_NameView)
if (!null ErrMess) //-
then LoadOK = false // No such view
else
{ read(NameModFull, false, false) // Invis, don't load standard view
if (null NameDefault) //-
then clearDefaultViewForUser(p_mod)
else setDefaultViewForUser (p_mod, NameDefault)
LoadOK = currentView(p_mod) == p_NameView
}
} // end invisible mod loading named view
print "fView_LoadView; " LoadOK "\tName [" p_NameView "]: tcanRead " (canRead viu) "\tToLoad [" NameToLoad "]\n"
print "\tin module '" NameModFull "'\n"
return(LoadOK)
} // end fView_LoadView()
|
Re: Count objects in filtered view llandale - Mon Jan 09 18:19:36 EST 2012
You need "current = m" before "load(view "Myview")". If the module is already open I don't think the "read" command sets it current. And yes you cannot load a view in an invisible module.
const string cl_vStandard = "Standard view"
//*****************************************
bool fView_LoadView(Module p_mod, string p_NameView)
{ // Load the specified view in the open module, which can be either visible or invisible
// When NameView is null, presume to load the Standard view
// Always presume to ignore manual view changes if any.
// Calling programs may want to do this:
// for NameView in view(mod) do
// { if (!fView_LoadView(mod, NameView)) continue
// for col in mod do
// { deal with columns
// }
// } // end views in the Module
// Odd realities:
// When the module is already Visible, then you
// can 'load' the view, but re-opening the module does NOT load any view
// When the module is already INvisible, then you
// cannot 'load' the view, but re-opening the module does indeed load
// either the default view or the standard view.
// Thus, when invisible we temporarily change the default view for
// the user to the desired View, and change it back after
// reading the module, which loads the view.
// Also, when the standard view is loaded in this way, the
// name of the current view doesn't change, but the columns do.
if (null p_mod or
type(p_mod) != "Formal") return(false)
string NameToLoad, NameModFull, NameDefault, ErrMess
Item itm
View viu
bool LoadOK
Module mod1
if (null p_NameView or
p_NameView == cl_vStandard) //-
then NameToLoad = cl_vStandard
else NameToLoad = p_NameView
NameModFull = fullName(p_mod)
itm = item(NameModFull)
viu = view(itm, NameToLoad) // Gets handle even if view doesn't exist
if (null viu or
!canRead(viu))
LoadOK = false // No such view, or user cannot see it.
elseif(isVisible(p_mod))
{ noError()
LoadOK = load(p_mod, viu, false)
ErrMess = lastError()
}
elseif(NameToLoad == cl_vStandard)
{ // ** Invisible Mod, loading the Standard view
LoadOK = p_mod == (Module read(NameModFull, false, true)) // Open, option to read Standard View
}
else
{ // ** Invisible Mod, loading a user view
NameDefault = getDefaultViewForUser(p_mod)
ErrMess = setDefaultViewForUser(p_mod, p_NameView)
if (!null ErrMess) //-
then LoadOK = false // No such view
else
{ read(NameModFull, false, false) // Invis, don't load standard view
if (null NameDefault) //-
then clearDefaultViewForUser(p_mod)
else setDefaultViewForUser (p_mod, NameDefault)
LoadOK = currentView(p_mod) == p_NameView
}
} // end invisible mod loading named view
print "fView_LoadView; " LoadOK "\tName [" p_NameView "]: tcanRead " (canRead viu) "\tToLoad [" NameToLoad "]\n"
print "\tin module '" NameModFull "'\n"
return(LoadOK)
} // end fView_LoadView()
|
Re: Count objects in filtered view mcnairk - Tue Jan 10 09:17:19 EST 2012 |
Re: Count objects in filtered view BDavenport - Fri Jan 06 12:39:19 EST 2012
One alternative I would suggest is to potentially approach this query from the prospective of the complex filter rather than the view. After all, the view is just a collection of attributes to display, it's the filter that identifies the content. Module mod = current Module int total_accepted = 0 int total_rejected = 0 Filter Reqt = (attribute "Requirement?" == "True") Filter Version = (attribute "Version" == "1") Filter Effectivity = (attribute "Effectivity" == "1.5") Filter Ver1Effcount = (Reqt && Version && Effectivity) set(current Module, Ver1Effcount, total_accepted, total_rejected)
For example I would like to create a filter to Filter on SHALL statements and count the number that have links. It would be great if I can make it something like Filter hasLinksCount = (SHALL && hasLinks) Thanks. |
Re: Count objects in filtered view SystemAdmin - Mon Nov 19 13:23:58 EST 2012 Filter hasLinks(LinkFilter value, string linkModName) |
Re: Count objects in filtered view Peter_Albert - Tue Nov 20 03:58:26 EST 2012 Filter hasLinks(LinkFilter value, string linkModName) |